
package pkg.andru.database;

public class SQLBuilder<T> {

    public static final String TYPE_INT = "INT";

    public static final String TYPE_TEXT = "TEXT";

    public static final String TYPE_VARCHAR = "VARCHAR(#)";

    public static final String TYPE_DATE = "DATE";

    public static final String END = ");";

    protected StringBuffer statement;

    /**
     * begin to combine the sql
     * 
     * @return T
     */
    @SuppressWarnings("unchecked")
    public T begin() {
        statement = new StringBuffer();
        return (T) this;
    }

    /**
     * end the sql combine
     * 
     * @return T
     */
    @SuppressWarnings("unchecked")
    public T end() {
        statement.append(END);
        return (T) this;
    }

    /**
     * ensure the sql string create.
     * 
     * @return
     */
    public String compileString() {
        return statement.toString();
    }

    /**
     * when build ok, you can reset it, reusing this object.
     */
    public void reset() {
        statement = null;
    }

}
